package com.yuan.algorithms.acm201503;

import java.util.Scanner;

public class HD1241查找油田 {

	static char[][] x;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int sum = 0;
			if (n==0 && m == 0) {
				continue;
			}
			x = new char[n][m];
			for (int i = 0; i < n; i++) {
				String a = sc.next();
				for (int j = 0; j < m; j++) {
					x[i][j] = a.charAt(j);
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (x[i][j]=='@') {
						f(i,j);
						sum++;
					}
				}
			}
			System.out.println(sum);
		}
	}

	private static void f(int i, int j) {
		if (i<0 || j<0 || i>=x.length || j>=x[i].length) {
			return;
		}
		if (x[i][j]=='@') {
			x[i][j] = '*';
			f(i+1, j);
			f(i+1, j+1);
			f(i, j+1);
			f(i-1, j+1);
			f(i-1, j);
			f(i-1, j-1);
			f(i, j-1);
			f(i+1, j-1);
		}
	}
}
